﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Threading;
using System.Globalization;

/// <summary>
/// PageBase 的摘要说明
/// 李贞赛
/// </summary>
public class PageBase : System.Web.UI.Page
{
	public PageBase()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
        this.Load += new EventHandler(Basepage_Load);
    }


    public void Basepage_Load(Object sender, EventArgs e)
    {
        if (Session["LoginUser"] == null)
        {
            System.Diagnostics.Debug.WriteLine("超时");
            //string s = "<script>{alert('登陆超时，请 重新登 录！');top.location.href='/login_main.aspx';}</script>";
            //ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script> alert('" + s + "')</script>");
            Response.Write(" <script> top.location.href= 'login.aspx'; </script> ");
            return;
        }
    }


    protected override void InitializeCulture()
    {
        
    }
    //显示信息到画面
    public void Alert(string message)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(),Guid.NewGuid().ToString(),"<script language=\"JavaScript\">" + GetAlert(message) + "</script>");
    }

    public string  GetAlert(string message)
    {
        return "alert('" + message.Replace("'", "\'") + "');";
    }
     
    public void WindowOpen(string url,string tager)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "<script language=\"JavaScript\">" + GetWindowOpen(url,tager ) + "</script>");
    }


    public string GetWindowOpen(string url, string tager)
    {
        return "window.open('" + url.Replace("'", "\'") + "'" + ",'" + tager.Replace("'", "\'") + "');"; ////swapPageEdit();
    }

    public void WindowOpen(string url, string tager,string paramaters)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "<script language=\"JavaScript\">" + GetWindowOpen(url, tager, paramaters) + "</script>");
    }


    public string GetWindowOpen(string url, string tager, string paramaters)
    {
        return "window.open('" + url.Replace("'", "\'") + "'" + ",'" + tager.Replace("'", "\'") + "','" + paramaters + "');"; ////swapPageEdit();
    }

    public void ShowModalDialogReturn(string value)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "<script language=\"JavaScript\">" + GetShowModalDialogReturn(value) + "</script>");
    }

    public string GetShowModalDialogReturn(string value)
    {
        return "window.returnValue ='" + value.Replace("'", "\'") + "';";
    }

    public void WindowClose(string url)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "<script language=\"JavaScript\">" + GetWindowClose(url) + "</script>");
    }

    public string GetWindowClose(string url)
    {
        return "window.opener.location='" + url.Replace("'", "\'") + "';window.close();";

    }

    public void SetParentValue(string value, string controlName)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "<script language=\"JavaScript\">" + GetParentValue(value, controlName) + "</script>");
    }

    public string GetParentValue(string value, string controlName)
    {
        return "window.opener.document.getElementById('" + controlName.Replace("'", "\'") + "')" + ".value='" + value.Replace("'", "\'") + "';";
    }

    public void ShowModalDialog(string url, string width, string height, string clientTop, string clientLeft)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "<script language=\"JavaScript\">" + GetShowModalDialog(url, width, height, clientTop, clientLeft) + "</script>");
    }

    public void ShowModalDialog(string url, string width, string height)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "<script language=\"JavaScript\">" + GetShowModalDialog(url, width, height) + "</script>");
    }

    public string GetShowModalDialog(string url, string width, string height, string clientTop, string clientLeft)
    {
        string strParams = "Minimize:yes;Maximize:yes;dialogWidth:" + width + "px; dialogHeight:" + height + "px;dialogTop:" + clientTop + "px;dialogLeft:" + clientLeft + "px;status:no; directories:no; scrollbars:no; resizable:off;center:no;";
        return "window.showModalDialog('" + url.Replace("'", "\'") + "'" + ",window,'" + strParams + "');";
    }
    public string GetShowModalDialog(string url, string width, string height)
    {
        string strParams = "Minimize:yes;Maximize:yes;dialogWidth:" + width + "px;status:no; directories:no; scrollbars:no; resizable:off;center:yes;";
        return "window.showModalDialog('" + url.Replace("'", "\'") + "'" + ",window,'" + strParams + "');";
    }
    public void ExecuteScript(string script)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "<script language=\"JavaScript\">" + script + "</script>");
    }



}
